<?php
	####################################################
	# QueryString 쿼리스트링 제어                      #
	####################################################

	class QueryString {
		# 쿼리 스트링의 구분자 값을 GET값으로 넘기기 위해 &을 |로 변형 시키고 리턴.
		#	example)
		#		replace >> gallery.php?mode=v&puid=1629&auid=0&nm=4 >> gallery.php?mode=v|puid=1629|auid=0|nm=4
		public static function polymoph(){
			$url = $_SERVER['REQUEST_URI'];
			$url = str_replace("&","|",$url);
			return $url;
		}

		# 위 멤버의 역정렬 형태.
		#parse >> gallery.php?mode=v|puid=1629 >> gallery.php?mode=v&puid=1629
		public static function unpolymoph($url) {
			$url = str_replace("|","&",$url);
			return $url;
		}

		# 쿼리스트링 정리
		# echo arrange("http://n.com/search.php?a=b&c=d&e=f&g=h&i=&j=k");
		# http://n.com/search.php?a=b&c=d&e=f&g=h&i=&j=k >> http://n.com/search.php?a=b&c=d&e=f&g=h&j=k
		public static function arrange($query) {
			if ($query) {
				$queryarray = explode("&", $query);
				//Nlog::xmp($queryarray);
				$count = count($queryarray);
				foreach($queryarray as $key => $value) {
					$array2st = explode("=", $value);
					//Nlog::xmp($array2st);
					if ($array2st[1]) {
						if ($querystring) $querystring .= "&".$value;
						else $querystring = $value;
						//Nlog::xmp($querystring);
					}
				}
				return $querystring;
			} else {
				return "";
			}
		}

		# display("http://n.com/search.php?a=b&c=d&e=f&g=h&i=&j=k");
		#
		#	Array
		#	(
		#	    [full_querystring] => a=b&c=d&e=f&g=h&i=&j=k
		#	    [a] => b
		#	    [c] => d
		#	    [e] => f
		#	    [g] => h
		#	    [i] =>
		#	    [j] => k
		#	)
		#
		public static function display($q) {
			$query = substr($q,strpos($q,'?')+1,strlen($q));
			$queryarr = explode("&", $query);
			//Nlog::xmp($queryarr);
			$questr["full_querystring"] = $query;
			foreach($queryarr as $k=>$v){
				$array2st = explode("=", $v);
				$questr[$array2st[0]] = $array2st[1];
			}
			//echo $query;
			Nlog::xmp($questr);
		}
	}

?>